package com.tbit.api;

import com.tbit.common.constant.OperationPlatform;
import com.tbit.common.entity.view.Result;
import com.tbit.manager.api.UserApi;
import com.tbit.manager.api.dto.UserDTO;
import com.tbit.uqbike.constant.OperaPswConstant;
import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.service.business.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;


/**
 * 运维端用户管理实现
 *
 * @since 2024/11/28
 */
@RestController
@Slf4j
public class UserApiImpl implements UserApi {
    @Autowired
    private UserService userService;
    @Autowired
    private RideLogDetailsService rideLogDetailsService;


    @Override
    public void updateNameAuth(Integer userId, String name, String idNO, String opName, String opPhone) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setLoginUserPlatform(OperationPlatform.MAINTAIN.code);
        loginInfo.setName(opName);
        loginInfo.setPhone(opPhone);
        userService.updateNameAuth(userId, name, idNO, loginInfo);
    }

    @Override
    public void updateStudentAuth(Integer userId, Integer studentAuth, String studentIdNo) {
        userService.updateStudentAuth(userId, 1, studentIdNo);
    }

    @Override
    public void editNameAuth(Integer userId) {
        userService.editNameAuth(userId);
    }

    @Override
    public void editNameAuthCount(Integer userId) {
        userService.editNameAuthCount(userId);
    }

    @Override
    public Boolean clearArrears(UserDTO userDTO) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setAccountUserId(userDTO.getLoginUserAccountUserId());
        loginInfo.setName(userDTO.getLoginUserName());
        loginInfo.setPhone(userDTO.getLoginUserPhone());
        loginInfo.setLoginUserPlatform(OperationPlatform.MAINTAIN.code);
        Result<String> result = rideLogDetailsService.clearArrears(loginInfo, userDTO.getUserId());
        return result.isSuccess();
    }

    @Override
    public Boolean updateUser(UserDTO userDTO) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setLoginUserPlatform(userDTO.getLoginUserPlatform());
        loginInfo.setName(userDTO.getLoginUserName());
        loginInfo.setPhone(userDTO.getLoginUserPhone());
        int result = userService.updateUser(userDTO.getUserId(), userDTO.getPhone(), userDTO.getLoginUserAccountUserId(),
                userDTO.getReason(),loginInfo);
        return result > 0;
    }

    @Override
    public void rechargeMoney(UserDTO userDTO) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId(userDTO.getAccountId());
        loginInfo.setAccountUserId(userDTO.getLoginUserAccountUserId());
        loginInfo.setType(userDTO.getLoginUserType());
        loginInfo.setName(userDTO.getLoginUserName());
        loginInfo.setPhone(userDTO.getLoginUserPhone());
        loginInfo.setLoginUserPlatform(userDTO.getLoginUserPlatform());
        userService.recharge(userDTO.getUserId(), userDTO.getMoney(), userDTO.getRemark(), loginInfo);
    }

    @Override
    public void frozenDeposit(Integer userId, Integer depositState) {
        userService.frozenDeposit(userId, depositState);
    }
}
